import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;


public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int numberOfLines = Integer.parseInt(sc.nextLine());
		int i = 0;
		ArrayList list = new ArrayList(0);
		ArrayList results = new ArrayList(0);
		
		while(i++ < numberOfLines){
			String line = sc.nextLine();
			String[] numbers = line.split(" ");
			int[] inputs = new int[numbers.length];
			inputs[0] = Integer.parseInt(numbers[0].trim());
			inputs[1] = Integer.parseInt(numbers[1].trim());
			inputs[2] = Integer.parseInt(numbers[2].trim());
			list.add(inputs);
		}
		Solution solution = new Solution();
		
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			int[] object = (int[]) iterator.next();
			int amount = object[0], rate=object[1], wrapperExchangeCount=object[2];
			int numberOfChoclates = solution.getNumberOfChoclates(amount,rate);
			int choclateCount = numberOfChoclates + solution.getChoclateForWrappers(numberOfChoclates,wrapperExchangeCount);
			System.out.println(choclateCount);
		}
		sc.close();
	}
	
	public int getNumberOfChoclates(int amount, int rate){
		return amount/rate;
	}
	
	public int getChoclateForWrappers(int noOfChoclates,int wrapperExchangedForChoclates){
		
		if(noOfChoclates < wrapperExchangedForChoclates){
			return 0;
		}
		int quotient=0,remainder =0,tempQuotient =0;
		while(noOfChoclates >=wrapperExchangedForChoclates){
			tempQuotient =(noOfChoclates/wrapperExchangedForChoclates);
			quotient += tempQuotient;
			remainder += noOfChoclates%wrapperExchangedForChoclates;
			noOfChoclates = tempQuotient;
		}
		if(remainder >= wrapperExchangedForChoclates){
			quotient += remainder/wrapperExchangedForChoclates;
		} else if((remainder+tempQuotient) >= wrapperExchangedForChoclates){
			quotient += (remainder+tempQuotient)/wrapperExchangedForChoclates;
		}
		return quotient;
	}	
}
